﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CarExam.Common
{
    /// <summary>
    /// 日志记录
    /// </summary>
    public static class ClassLoger
    {
        public static bool logger(string type, string msg)
        {
            try
            {
                string LogPath = "D:\\logs";//日志路径
                string filePath = LogPath + "\\" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString();
                string fileName = filePath + "\\" + DateTime.Now.Day.ToString() + ".Log";
                if (!System.IO.Directory.Exists(filePath))
                {
                    System.IO.Directory.CreateDirectory(filePath);
                }
                FileStream filestream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
                StreamWriter writer = new StreamWriter(filestream, System.Text.Encoding.Default);
                writer.BaseStream.Seek(0, SeekOrigin.End);
                writer.WriteLine("{0} > {1} > {2}", DateTime.Now.TimeOfDay, type, msg);
                writer.Flush();
                writer.Close();
                filestream.Close();
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }

    }
}
